package com.core.gwt.place.client;

/**
 * An abstract implementation of {@link Mode}.
 * 
 * 
 * 
 */
public abstract class AbstractMode implements Mode {
	protected Mode.Handler handler;

	@Override
	public final void cancel() {
		exit();
	}

	@Override
	public final void enter(final Handler handler) {
		this.handler = handler;
		onEnter();
	}

	/**
	 * Implementation should call this method to exit the mode. It calls
	 * {@link #onExit()} and {@link Mode.Handler#onExit()}.
	 */
	protected final void exit() {
		onExit();
		handler.onExit();
	}

	/**
	 * Implement to set up and show the mode UI.
	 */
	protected abstract void onEnter();

	/**
	 * Implement to clean up and hide the mode UI.
	 */
	protected abstract void onExit();
}
